﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using Microsoft.Phone.Controls;
using Microsoft.Phone.Shell;
using XBMCRemote.DataModel.Entities;
using XBMCRemote.UseCase;

namespace XBMCRemote
{
    public partial class ConnectionsPage : PhoneApplicationPage
    {		
        ConfigurationUseCase _configurationUseCase;
		
        public ConnectionsPage()
        {
            InitializeComponent();
			
            _configurationUseCase = (App.Current as App).ConfigurationUseCase;

            lbConnections.ItemsSource = _configurationUseCase.GetAllConfigurations();
        }

        private void btnNew_Click(object sender, System.EventArgs e)
        {
            NavigationService.Navigate(new Uri("/SettingsPage.xaml", UriKind.Relative));
        }

        private void btnSettings_Click(object sender, System.EventArgs e)
        {
        	// TODO: Add event handler implementation here.
            var config = lbConnections.SelectedItem as Configuration;
            NavigationService.Navigate(new Uri("/SettingsPage.xaml?id=" + config.Id.ToString(), UriKind.Relative));
        }

        private void btnSelect_Click(object sender, System.EventArgs e)
        {
        	// TODO: Add event handler implementation here.
        }

        private void lbConnections_SelectionChanged(object sender, System.Windows.Controls.SelectionChangedEventArgs e)
        {
            var settingsButton = ApplicationBar.Buttons[1] as ApplicationBarIconButton;
            settingsButton.IsEnabled = true;
            var selectButton = ApplicationBar.Buttons[2] as ApplicationBarIconButton;
            selectButton.IsEnabled = true;
        }
    }
}
